<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','','',true);
	$type=intval($_RQ['type']);
	$return['setting']=$this->plugin_setting('page_setting');
	$params=array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
	if($type){
		$params['type']=$type;
	}else{
		$params['type >=']=1;
	}
	$return['commission_money']=$this->sum('commission',$params,'money');
	if(!$return['commission_money']){
		$return['commission_money']=0;
	}
	$return['commission_total']=$this->count('commission',$params);
	$levels=array();
	for($i=0;$i<$this->setting['level'];$i++){
		$level=$i+1;
		$levels[$i]['key']=$level;
		$levels[$i]['title']=$this->setting['levelname'.$level]?:$level.'级';
		$levels[$i]['num']=$this->count('commission',array('mid'=>$_SESSION['uid'],'level'=>$level));
	}
	$return['levels']=$levels;
	$return['list']=array();
	$return['params']=array('type'=>$type);
	$type=intval($_RQ['type'])?:array(1,2,3,4,5);
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$lastdaytime = $daytime-24*3600;
	$data['type1inall']=pdo_getsum('jy_leijifee_commission',array('type'=>$type,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'money');
	$data['type1inall2']=pdo_getsum('jy_leijifee_commission',array('status'=>2,'type'=>$type,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'money');
	$data['type1inday']=pdo_getsum('jy_leijifee_commission',array('type'=>$type,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime),'money');
	$data['type1inlastday']=pdo_getsum('jy_leijifee_commission',array('type'=>$type,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'createtime between'=>array($lastdaytime,$daytime)),'money');
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	$return['member']=$member;
	$return['psize']=20;
	$return['setting']=$this->plugin_setting('page_setting');
	$return['setting']['balance_money']=$this->setting['balance_money'];
	$diytitle=array('tagent','tshop','tmyshop','tcenter','tbecome','balance_button','tcommission','tcommission1','commission_total','commission_1','balance_total','balance_1','commission_1_1','commission_0','balance_2','balance_3','balance_pay','tcommission_detail','torder','tdown','tmydown','area_title','commission_area');
	foreach($diytitle as $v){
		$return['setting'][$v]=$return['setting'][$v.'2']?:$return['setting'][$v];
	}
	$data['commission_total']=$this->sum('commission',array('mid'=>$_SESSION['uid'],'type >='=>1),'money');
	$data['fee2']=$this->sum('commission',array('mid'=>$_SESSION['uid'],'type'=>2,'uniacid'=>$_SESSION['uniacid']),'money');
	$data['fee3']=$this->sum('commission',array('mid'=>$_SESSION['uid'],'type'=>3,'uniacid'=>$_SESSION['uniacid']),'money');
	$data['fee4']=$this->sum('commission',array('mid'=>$_SESSION['uid'],'type'=>4,'uniacid'=>$_SESSION['uniacid']),'money');
	$data['fee5']=$this->sum('commission',array('mid'=>$_SESSION['uid'],'type'=>5,'uniacid'=>$_SESSION['uniacid']),'money');
	$data['fee6']=$this->sum('commission',array('mid'=>$_SESSION['uid'],'type'=>array(6,7),'uniacid'=>$_SESSION['uniacid']),'money');
	$data['balance_pay']=pdo_getsum('core_member_cash',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'service_money');	
	foreach($data as &$row){
		$row=price($row);
	}
	$return['data']=$data;
	$cash=uni_setting('cash');
	$return['cash']=$cash;
	set_html('title','分佣明细');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['type']){
		$params['type']=$_RQ['type'];
	}
	if($_RQ['ordersn']){
		$params['ordersn']=$_RQ['ordersn'];
	}
	if($params['type']==2){
		$params['type']=array(2,3,4,5);
	}
	if($params['type']==6){
		$params['type']=array(6,7);
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('commission',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['status']=$this->model('model')->uplastfee($item);
		$item['member']=model('core/member')->basic($item['ordermid']);
		$item['statustitle']=$this->commission_status[$item['status']];	
		$item['typetitle']=$this->commission_money_types[$item['type']];
		$item['createtime']=date('Y-m-d H:i',$item['createtime']);
	}
	exi($list);
}
?>